import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'


Vue.component('child', {
    render: function (h: Function) {
        console.log(this.$slots.default, "nandenande")
        return h(
            'wl-states',
            "diunitiaopujie"
        )
    },
    props: {
        level: {
            type: Number,
            required: true
        }
    }
})

@Component({
})
export default class vuets extends Vue {
    private jsonData: any
    constructor() {
        super();
        this.jsonData = {
            code: 0,
            data: {
                id: 83,
                bianhao: "编号",
                cangkumingchen: "仓库名称",
                shifumoren: "shi",
                suoshudanwei: {
                    id: 76,
                    danweimingchen: "单位名称"
                },
                cangkufuzeren: {
                    id: 13,
                    zhanghao: "账号"
                },
                cangguanyuan: [
                    {
                        id: 4,
                        zhanghao: "账号",
                        yonghuxinxi: {
                            dianhua: "电话",
                            xingbie: "nan",
                            bumen: [
                                {
                                    id: 64,
                                    bumenmingchen: "部门名称"
                                }
                            ],
                            jiaose: [
                                {
                                    id: 35,
                                    jiaosemingchen: "角色名称"
                                }
                            ]
                        }
                    }
                ],
                cangkuquyu: [
                    {
                        id: 44,
                        quyubianma: "区域编码",
                        quyumingchen: "区域名称",
                        zongxing: 21,
                        zonglie: 24,
                        zhuangtai: "zhengchang",
                        shuoming: "说明",
                        beizhu: "备注",
                        cangkuhuowei: [
                            {
                                id: 50,
                                bianhao: "货位编号"
                            },
                            {
                                id: 51,
                                bianhao: "货位编号-1"
                            }
                        ]
                    },
                    {
                        id: 11,
                        quyubianma: "区域编码-11",
                        quyumingchen: "区域名称-11",
                        zongxing: 21,
                        zonglie: 24,
                        zhuangtai: "zhengchang",
                        shuoming: "说明",
                        beizhu: "备注",
                        cangkuhuowei: [
                            {
                                id: 53,
                                bianhao: "货位编号-3"
                            },
                            {
                                id: 54,
                                bianhao: "货位编号-4"
                            }
                        ]
                    }
                ]
            },
            msg: ""
        };

        var conf = this.createJsonConf(this.jsonData, "", 0);
        console.log(conf, "fkpwkl")
    }

    createJsonConf = (json: any, parentKey: string, level: number): any => {
        parentKey = parentKey.replace(WLConst.reg.firstDot, '');
        if (wlIsObject(json)) {
            let outerConf: JsonConf = {} as any;
            outerConf.key = parentKey;
            outerConf.list = [];
            outerConf.type = 'object';
            outerConf.level = level;
            outerConf.flag = true;
            outerConf.selected = false;

            for (var key in json) {
                let conf: JsonConf = this.createJsonConf(json[key], parentKey + '.' + key, level + 1);
                conf.prop = key;
                outerConf.list.push(conf);
            }
            return outerConf;
        } else if (wlIsArray(json)) {
            let outerConf: JsonConf = {} as any;
            outerConf.type = 'array';
            outerConf.flag = true;
            outerConf.list = [];
            outerConf.selected = false;
            outerConf.key = parentKey;
            json.forEach((item: any, ind: number) => {
                let tmpConf: JsonConf = this.createJsonConf(item, parentKey + '[' + ind + ']', level + 1);
                tmpConf.prop = ind + '';
                outerConf.list.push(tmpConf);
            });

            return outerConf;
        } else if (wlIsString(json)) {
            let outerConf: JsonConf = {} as any;
            outerConf.type = 'string';
            outerConf.key = parentKey + '.string';
            outerConf.prop = parentKey;
            outerConf.level = level;
            outerConf.excelFormula = '';
            outerConf.selected = false;
            return outerConf;
        } else if (wlIsNumber(json)) {
            let outerConf: JsonConf = {} as any;
            outerConf.type = 'number';
            outerConf.key = parentKey + '.number';
            outerConf.prop = parentKey;
            outerConf.level = level;
            outerConf.excelFormula = '';
            outerConf.selected = false;
            return outerConf;
        } else if (wlIsBoolean(json)) {
            let outerConf: JsonConf = {} as any;
            outerConf.type = 'boolean';
            outerConf.key = parentKey + '.boolean';
            outerConf.prop = parentKey;
            outerConf.level = level;
            outerConf.excelFormula = '';
            outerConf.selected = false;
            return outerConf;
        } else {
            let outerConf: JsonConf = {} as any;
            outerConf.type = 'none';
            outerConf.key = parentKey + '.none';
            outerConf.prop = parentKey;
            outerConf.level = level;
            outerConf.excelFormula = '';
            outerConf.selected = false;
            return outerConf;
        }
    }
}